package com.yanfan.zutai.controller;

import com.yanfan.common.core.controller.BaseController;
import com.yanfan.common.core.domain.AjaxResult;
import com.yanfan.common.core.page.TableDataInfo;
import com.yanfan.common.utils.SecurityUtils;
import com.yanfan.common.utils.poi.ExcelUtil;
import com.yanfan.zutai.domain.BDeviceModel;
import com.yanfan.zutai.service.IBDeviceModelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 三维配置Controller
 *
 * @author ruoyi
 * @date 2022-07-25
 */
@RestController
@RequestMapping("/zutai/bDeviceModel")
public class BDeviceModelController extends BaseController {
    @Autowired
    private IBDeviceModelService bDeviceModelService;

    /**
     * 查询三维配置列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BDeviceModel bDeviceModel) {
        startPage();
        if (!SecurityUtils.getUsername().equals("admin")) {
            bDeviceModel.setUserName(SecurityUtils.getUsername());
            bDeviceModel.setStatus(1);
        }
        List<BDeviceModel> list = bDeviceModelService.selectBDeviceModelList(bDeviceModel);
        return getDataTable(list);
    }

    /**
     * 导出三维配置列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, BDeviceModel bDeviceModel) {
        List<BDeviceModel> list = bDeviceModelService.selectBDeviceModelList(bDeviceModel);
        ExcelUtil<BDeviceModel> util = new ExcelUtil<BDeviceModel>(BDeviceModel.class);
        util.exportExcel(response, list, "三维配置数据");
    }

    /**
     * 获取三维配置详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(bDeviceModelService.selectBDeviceModelById(id));
    }

    /**
     * 新增三维配置
     */
    @PostMapping
    public AjaxResult add(@RequestBody BDeviceModel bDeviceModel) {
        return toAjax(bDeviceModelService.insertBDeviceModel(bDeviceModel));
    }

    /**
     * 修改三维配置
     */
    @PutMapping
    public AjaxResult edit(@RequestBody BDeviceModel bDeviceModel) {
        return toAjax(bDeviceModelService.updateBDeviceModel(bDeviceModel));
    }

    /**
     * 删除三维配置
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(bDeviceModelService.deleteBDeviceModelByIds(ids));
    }
}
